package com.lzx.iteam;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.util.StringUtil;

import java.util.ArrayList;

/**
 * Created by zhangshuai on 15-5-20.
 */
public class ResultActivity extends Activity implements View.OnClickListener{

    private TextView mTvName;
    private TextView mTvPhone;
    private TextView mTvCompany;
    private TextView mTvJob;
    private TextView mTvEmail;
    private TextView mTvAddress;
    private ImageView mIvAvatar;
    private Button mBtnAdd;
    private LinearLayout mBack;

    private String mName,mPhone,mPhoneMore,mCompany,mJob,mEmail,mAddress;
    private ArrayList<String> mDataList;

    public static final String QRCODE_DATA = "data";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.result_card_layout);
        mDataList = new ArrayList<String>();
        getData();
        initView();
        setData();

    }

    public void getData(){
        Intent intent = getIntent();
        mName = intent.getStringExtra("name");
        mPhone = intent.getStringExtra("phone");
        //mPhoneMore = intent.getStringExtra("landline");
        mCompany = intent.getStringExtra("company");
        mJob = intent.getStringExtra("job");
        mAddress = intent.getStringExtra("address");
        mEmail = intent.getStringExtra("email");
    }

    public void initView(){
        mTvName = (TextView) findViewById(R.id.cloud_contact_detail_name);
        mTvPhone = (TextView) findViewById(R.id.cloud_contact_detail_phone);
        mTvCompany = (TextView) findViewById(R.id.cloud_contact_detail_company);
        mTvJob = (TextView) findViewById(R.id.cloud_contact_detail_position);
        mTvEmail = (TextView) findViewById(R.id.cloud_contact_detail_email);
        mTvAddress = (TextView) findViewById(R.id.cloud_contact_detail_address);
        mBtnAdd = (Button) findViewById(R.id.result_btn_add);
        mBtnAdd.setOnClickListener(this);
        mIvAvatar = (ImageView) findViewById(R.id.result_card_photo);
        mBack = (LinearLayout) findViewById(R.id.result_ll_back);
        mBack.setOnClickListener(this);
    }

    public void setData(){
        mTvName.setText(mName);
        String phone = mPhone;
        /*if (!StringUtil.isEmpty(mPhoneMore)){
            phone = mPhone +"  "+ mPhoneMore;
        }*/
        mTvPhone.setText(phone);

        if (!StringUtil.isEmpty(mCompany)){
            mTvCompany.setText(mCompany);
        }
        if (!StringUtil.isEmpty(mJob)){
            mTvJob.setText(mJob);
        }
        if (!StringUtil.isEmpty(mEmail)){
            mTvEmail.setText(mEmail);
        }
        if (!StringUtil.isEmpty(mAddress)){
            mTvAddress.setText(mAddress);
        }

        /*if (!StringUtil.isEmpty(mAvatar)){
            DownloadImageTask downloadImageTask = new DownloadImageTask(mIvAvatar);
            downloadImageTask.execute(mAvatar);
        }*/
        addData();
    }

    public void addData(){
        mDataList.add(mName);
        mDataList.add(mPhone);
        mDataList.add("");
        mDataList.add(mCompany);
        mDataList.add(mJob);
        mDataList.add(mEmail);
        mDataList.add(mAddress);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.result_ll_back:
                finish();
                break;
            case R.id.result_btn_add:
                Intent intent = new Intent(this,QrCodeAddActivity.class);
                intent.putStringArrayListExtra(QRCODE_DATA,mDataList);
                startActivity(intent);
                break;
        }
    }
}
